package org.hot100_0.leetcode141;

import org.leetcode.easy.ListNode;

public class Solution {
    public boolean hasCycle(ListNode head) {

        if (head==null || head.next==null){
            return  false;
        }

        ListNode slow = head;
        ListNode fast = head.next;


        while (fast!=null){

            if (fast==slow){
                return true;
            }

            slow = slow.next;
            fast = fast.next;
            if (fast!=null){
                fast=fast.next;
            }
        }
        return false;
    }
}
